package com.snow.storeapi.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.snow.storeapi.entity.Disease;
import com.snow.storeapi.entity.McodeContent;
import com.snow.storeapi.entity.ScodeContent;
import com.snow.storeapi.service.IDiseaseService;
import com.snow.storeapi.service.IMcodeContentService;
import com.snow.storeapi.service.IScodeContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dict")
public class DictController {
    @Autowired
    private IMcodeContentService mcodeContentService;

    @Autowired
    private IScodeContentService scodeContentService;

    @Autowired
    private IDiseaseService diseaseService;

    @GetMapping("/complex")
    public List<McodeContent> complex() {
        List<McodeContent> mcodeContents = mcodeContentService.list(new QueryWrapper<McodeContent>().eq("use_state", "1")
                .orderByAsc("region_code", "order_no"));
        return mcodeContents;
    }

    @GetMapping("/simple")
    public List<ScodeContent> simple() {
        List<ScodeContent> scodeContents = scodeContentService.list(new QueryWrapper<ScodeContent>().eq("use_state", "1")
        .likeRight("region_code", "DTM").orderByAsc("region_code", "order_no"));
        return scodeContents;
    }

    @GetMapping("/disease")
    public List<Disease> getDisease(@RequestParam(value = "diseaseName", defaultValue = "") String diseaseName) {
        List<Disease> diseases;
        if (!"".equals(diseaseName)) {
            diseases = diseaseService.selectByPage(diseaseName);
        } else {
            diseases = diseaseService.topTen();
        }
        return diseases;
    }
}
